<template>
    <div class="signInBox">
        <div class="headBox">
            <img src="../assets/images/bgimgright12x.png" alt/>
            <div class="headContent flex_sb">
                <div></div>
                <router-link to="login" class="rightBox">登录</router-link>
            </div>
        </div>
        <!-- 步骤一账号注册 -->
        <div class="loginContent">
            <div class="loginTitle">新用户注册</div>
            <div class="formList flex">
                <input type="text" class="inputBox" v-model="userName" placeholder="请输入用户名"/>
            </div>

            <div class="formList flex">
                <input :type="see?'text':'password'" class="inputBox" v-model="passWord" placeholder="请输入密码"/>
                <img v-if="!see" src="../assets/images/icon_Nodisplay02x.png" class="seeBtn" @click="see=!see"/>
                <img v-else src="../assets/images/icon_display02x.png" alt class="seeBtn" @click="see=!see"/>
            </div>
            <div class="formList flex">
                <div class="leftHint">+86</div>
                <input type="text" class="inputBox" v-model="userPhone" placeholder="请输入手机号"/>
            </div>
            <div class="formList flex">
                <input class="inputBox" v-model="authCode" placeholder="请输入验证码" @blur.native="sendMobile"/>
                <div v-if="!countDown" class="authBtn" @click="getAuthCode">获取验证码</div>
                <div v-if="countDown" class="second">{{secondDown}}s</div>
                <input type="hidden" id="phoneCode" v-model="phoneCode"/>
            </div>
            <div class="handleBox flex_sb" style="display: none">
                <div class="goAuthCode">可发短信给润禾教育平台</div>
            </div>
            <div class="protocol flex">
                <check-icon :value.sync="checkProtocol"></check-icon>
                <router-link to="/user-agreement" class="protocolInfo">同意《用户使用协议》</router-link>
            </div>
            <div
                    class="loginBtn"
                    :class="checkProtocol==true&&userPhone!==''&&userName!==''&&passWord!==''&&authCode!==''?'active':''"
                    @click="goInBtn()"
            >注册
            </div>
            <!--            <router-link to class="moreGoIn">收不到验证码</router-link>-->
        </div>
    </div>
</template>

<script>
    import {CheckIcon, Confirm, Divider, Datetime, Group, XInput,} from 'vux'
    import Upload from '../components/Uploader'
    import {getVerificationCode, register} from '@/api/index/login';
    import store from "../store/store";

    export default {
        components: {
            Upload,
            CheckIcon,
            Confirm,
            Divider,
            Datetime,
            Group,
            XInput,
        },
        data() {
            return {
                userName: '',
                userPhone: '',
                passWord: '',
                authCode: '',
                phoneCode: '',
                checkProtocol: false,
                secondDown: 60,
                see: false,
                countDown: false,
                userInfo: [],
            }
        },
        methods: {
            // 验证码倒计时
            getAuthCode() {
                //验证手机号码
                let mobile = this.userPhone;
                //正则校验手机号是否合法
                if (!(/^1(3|4|5|7|8|9)\d{9}$/.test(mobile))) {
                    this.$vux.alert.show({
                        content: '手机号格式错误'
                    });
                    this.userPhone = '';
                    return
                }
                // 发送验证码请求
                // this.$http.get('url').then(res => {
                // })
                getVerificationCode(mobile, '4ZMNZFG4CM').then(res => {
                    console.log(res.data.data);
                    this.phoneCode = res.data.data.phoneCode;
                }).catch(err => {
                    console.log(err);
                });


                // 显示倒计时
                this.countDown = true
                // 设置倒计时
                this.intervalBtn = setInterval(() => {
                    if (this.secondDown <= 0) {
                        this.countDown = false
                        // 清除定时器
                        clearInterval(this.intervalBtn)
                        // 重置倒计时状态
                        this.secondDown = 60;
                    }
                    ;
                    // 倒计时
                    this.secondDown--;
                }, 1000);
            },
            goInBtn() {
                console.log(this.userName);
                console.log(this.userPhone);
                console.log(this.passWord);
                console.log(this.authCode);
                console.log(this.phoneCode);
                if (this.$store.state.user.tenantId == '' || this.$store.state.user.tenantId == undefined) {
                    var tenantId = "4ZMNZFG4CM";
                } else {
                    var tenantId = this.$store.state.user.tenantId;
                }
                if (this.authCode == this.phoneCode) {
                    register(this.userName, this.userPhone, this.passWord, tenantId).then(res => {
                        console.log(res.data.data.userInfo);
                        if (res.data.data.message == 0) {
                            alert("手机号已注册");
                        } else if (res.data.data.message == 1) {
                            this.userInfo = res.data.data.userInfo;
                            if (res.data.data.userInfo != null) {
                                alert("注册成功");
                                this.$router.push("/");
                            }
                        }

                    }).catch(err => {
                        console.log(err)
                    });
                }
                // if (this.passType == 'passWord') {
                //   loginIn(this.userName, md5(this.passWord)).then(res => {
                //     // console.log(res.data.data.userInfo);
                //     if (res.data.data.userInfo!= null) {
                //       this.$router.push("/");
                //     } else {
                //       console.log("1111");
                //       showMessage("登陆失败");
                //       // this.pushMessage();
                //     }
                //   }).catch(err => {
                //     console.log(err)
                //   });
                //   // this.$http.get('url', {
                //   //   params: {
                //   //     userName: this.userName,
                //   //     passWord: this.passWord
                //   //   }
                //   // }).then(res => {
                //   //   // 成功相应
                //   // })
                // } else {
                //   // this.$http.get('url', {
                //   //   params: {
                //   //     userName: this.userName,
                //   //     passWord: this.passWord
                //   //   }
                //   // }).then(res => {
                //   // })
                // }
            },

        }
    }
</script>

<style lang="less" scoped>
    .signInBox {
        background-color: #fff;

        .headBox {
            position: relative;
            padding: 20px;

            img {
                position: absolute;
                top: 0;
                right: 0;
                width: 180px;
            }

            .headContent {
                padding-top: 30px;
                font-size: 34px;

                .leftBox {
                    color: #04aaff;
                    font-size: 34px;
                }

                .rightBox {
                    display: inline-block;
                    color: #04aaff;
                    border-radius: 40px;
                    border: 2px solid #04aaff;
                    text-align: center;
                    line-height: 80px;
                    height: 80px;
                    width: 140px;
                    background-color: #fff;
                    z-index: 3;
                }
            }
        }

        .loginContent {
            padding: 40px 80px;

            .loginTitle {
                font-size: 50px;
                font-weight: bold;
                padding: 40px 0;
            }

            .formList {
                // padding: 40px 0;
                height: 100px;
                border-bottom: 2px solid #f0f0f0;

                .leftHint {
                    background-color: #f6f6fe;
                    color: #798696;
                    padding: 2px 10px;
                    margin-right: 20px;
                    font-size: 32px;
                    border-radius: 10px;
                }

                .inputBox {
                    border: none;
                    outline: none;
                    font-size: 32px;
                    flex-grow: 1;
                    padding: 0 10px;
                    width: 100px;
                    height: 60px;
                }

                .seeBtn {
                    width: 50px;
                }

                .authBtn {
                    font-size: 30px;
                    color: #04aaff;
                    flex-shrink: 0;
                }

                .second {
                    font-size: 30px;
                    color: #04aaff;
                }
            }

            .handleBox {
                padding: 20px 0;
                font-size: 30px;
                color: #798696;

                .forget {
                    color: #798696;
                }
            }

            .protocol {
                padding: 20px 0;

                /deep/ .weui-icon-success:before {
                    color: #04aaff;
                }

                .protocolInfo {
                    font-size: 30px;
                    color: #767676;
                    margin-left: 10px;
                }
            }

            .loginBtn {
                margin-top: 40px;
                text-align: center;
                padding: 16px 40px;
                border-radius: 40px;
                font-size: 36px;
                background-color: rgb(209, 206, 206);
            }

            .loginBtn.active {
                background: linear-gradient(60deg, #98d8ff, #06a9f5);
                color: #fff;
            }

            .moreGoIn {
                position: absolute;
                bottom: 50px;
                left: 0;
                right: 0;
                text-align: center;
                color: #798696;
                font-size: 36px;
            }
        }
    }
</style>